package com.ogilvy.cms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ogilvy.cms.bean.CmsResource;
import com.ogilvy.cms.dao.CmsResourceDao;
import com.ogilvy.cms.service.CmsResourceService;
import com.ogilvy.frame.service.BaseServiceImpl;

@Service
public class CmsResourceServiceImpl extends BaseServiceImpl implements CmsResourceService{

	@Autowired
	protected  CmsResourceDao cmsResourceDao;
	
	public CmsResource add(CmsResource cmsResource) {
		CmsResource  crs = cmsResourceDao.save(cmsResource);
		return crs;
	}

	public boolean del(Integer cmrId) {
		cmsResourceDao.deleteById(cmrId);
		return true;
	}

	public boolean modify(CmsResource cmsResource) {
		cmsResourceDao.update(cmsResource);
		return true;
	}

	public List<CmsResource> query(CmsResource cmsResource) {
		System.out.println("serviceimp 获取的资源名字::"+cmsResource.getCmrName());
		if(isEmpty(cmsResource.getCmrName())){
			return cmsResourceDao.findAll();
		}
		//error
		return cmsResourceDao.findByProperty("cmrName", cmsResource.getCmrName());	
		
	}
	//通过ID进行资源查询
	public CmsResource get(Integer cmrId) {
		return cmsResourceDao.get(cmrId);
	}

}
